﻿Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
    End Sub
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        ' Try
        'Dim cid As String = GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text
        'cn.Open()
        'Dim cmd As New SqlCommand("delete from comment where commentid=" + cid, cn)
        'Dim i As Integer = cmd.ExecuteNonQuery()
        'GridView1.SelectedIndex = -1
        'GridView1.DataBind()
        'Catch
        'End Try
        functions.delcomment(GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text)
        GridView1.SelectedIndex = -1
        GridView1.DataBind()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label2.Text = Session("username")
        Try
            Dim cmd As New SqlCommand("select commentid,comment,imageurl,commentby from comment,imagetable  where comment.imageid=imagetable.imageid order by cdate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cmd As New SqlCommand("select commentid,comment,imageurl,commentby from comment,imagetable  where comment.imageid=imagetable.imageid order by cdate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim cmd As New SqlCommand("select commentid,comment,imageurl,commentby from comment,imagetable  where comment.imageid=imagetable.imageid and commentby='" + DropDownList1.SelectedValue + "' order by cdate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try

    End Sub

End Class
